Computer Science Programming Basics with Ruby

Computer Science Programming Basics with Ruby
Author: Ophir Frieder, Gideon Frieder & David Grossman
Language: eng
Format: epub
ISBN: 9781449355975
Publisher: O’Reilly Media, Inc.
Published: 2013-03-25

Example: Find the Max—Hash

Example 6-10. Find the max—hash

1 scores = Hash.new 2 3 scores["Geraldo"] = [98, 95, 93, 96] 4 scores["Brittany"] = [74, 90, 84, 92] 5 scores["Michael"] = [72, 87, 68, 54, 10] 6 7 maxscore = 0 8 for name in scores.keys 9 column = 0 10 while (column < scores[name].size) 11 12 if (scores[name][column] > maxscore) 13 maxname = name 14 maxscore = scores[name][column] 15 end 16 column = column + 1 17 end 18 end 19 20 puts maxname + " has the highest score." 21 puts "The highest score is: " + maxscore.to_s